home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Python 1.3 / source code / Doc / libimp.tex < prev    next >
LaTeX Document  |  1995-12-17  |  6.9 KB  |  [TEXT/R*ch]

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: LaTeX Document (document/latex).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert LaTeX Document (document/latex) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file LaTeX document text default
99% file LaTeX document, ASCII text, with CR line terminators default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/281 LaTeX (Subdocument) default
100% detectItEasy Format: plain text[CR] default (weak)


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[R*ch]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 5c 73 65 63 74 69 6f 6e | 7b 42 75 69 6c 74 2d 69 |\section|{Built-i|
|00000010| 6e 20 4d 6f 64 75 6c 65 | 20 5c 73 65 63 74 63 6f |n Module| \sectco|
|00000020| 64 65 7b 69 6d 70 7d 7d | 0d 5c 62 69 6d 6f 64 69 |de{imp}}|.\bimodi|
|00000030| 6e 64 65 78 7b 69 6d 70 | 7d 0d 5c 69 6e 64 65 78 |ndex{imp|}.\index|
|00000040| 7b 69 6d 70 6f 72 74 7d | 0d 0d 54 68 69 73 20 6d |{import}|..This m|
|00000050| 6f 64 75 6c 65 20 70 72 | 6f 76 69 64 65 73 20 61 |odule pr|ovides a|
|00000060| 6e 20 69 6e 74 65 72 66 | 61 63 65 20 74 6f 20 74 |n interf|ace to t|
|00000070| 68 65 20 6d 65 63 68 61 | 6e 69 73 6d 73 20 75 73 |he mecha|nisms us|
|00000080| 65 64 20 74 6f 20 69 6d | 70 6c 65 6d 65 6e 74 0d |ed to im|plement.|
|00000090| 74 68 65 20 5c 63 6f 64 | 65 7b 69 6d 70 6f 72 74 |the \cod|e{import|
|000000a0| 7d 20 73 74 61 74 65 6d | 65 6e 74 2e 20 20 49 74 |} statem|ent. It|
|000000b0| 20 64 65 66 69 6e 65 73 | 20 74 68 65 20 66 6f 6c | defines| the fol|
|000000c0| 6c 6f 77 69 6e 67 20 63 | 6f 6e 73 74 61 6e 74 73 |lowing c|onstants|
|000000d0| 20 61 6e 64 0d 66 75 6e | 63 74 69 6f 6e 73 3a 0d | and.fun|ctions:.|
|000000e0| 0d 5c 72 65 6e 65 77 63 | 6f 6d 6d 61 6e 64 7b 5c |.\renewc|ommand{\|
|000000f0| 69 6e 64 65 78 73 75 62 | 69 74 65 6d 7d 7b 28 69 |indexsub|item}{(i|
|00000100| 6e 20 6d 6f 64 75 6c 65 | 20 69 6d 70 29 7d 0d 0d |n module| imp)}..|
|00000110| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000120| 7b 67 65 74 5f 6d 61 67 | 69 63 7d 7b 7d 0d 52 65 |{get_mag|ic}{}.Re|
|00000130| 74 75 72 6e 20 74 68 65 | 20 6d 61 67 69 63 20 73 |turn the| magic s|
|00000140| 74 72 69 6e 67 20 76 61 | 6c 75 65 20 75 73 65 64 |tring va|lue used|
|00000150| 20 74 6f 20 72 65 63 6f | 67 6e 69 7a 65 20 62 79 | to reco|gnize by|
|00000160| 74 65 2d 63 6f 6d 70 69 | 6c 65 64 20 63 6f 64 65 |te-compi|led code|
|00000170| 0d 66 69 6c 65 73 20 28 | 60 60 5c 63 6f 64 65 7b |.files (|``\code{|
|00000180| 2e 70 79 63 7d 20 66 69 | 6c 65 73 27 27 29 2e 0d |.pyc} fi|les'')..|
|00000190| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|000001a0| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|000001b0| 7b 67 65 74 5f 73 75 66 | 66 69 78 65 73 7d 7b 7d |{get_suf|fixes}{}|
|000001c0| 0d 52 65 74 75 72 6e 20 | 61 20 6c 69 73 74 20 6f |.Return |a list o|
|000001d0| 66 20 74 72 69 70 6c 65 | 73 2c 20 65 61 63 68 20 |f triple|s, each |
|000001e0| 64 65 73 63 72 69 62 69 | 6e 67 20 61 20 70 61 72 |describi|ng a par|
|000001f0| 74 69 63 75 6c 61 72 20 | 74 79 70 65 20 6f 66 20 |ticular |type of |
|00000200| 66 69 6c 65 2e 0d 45 61 | 63 68 20 74 72 69 70 6c |file..Ea|ch tripl|
|00000210| 65 20 68 61 73 20 74 68 | 65 20 66 6f 72 6d 20 5c |e has th|e form \|
|00000220| 63 6f 64 65 7b 28 5c 76 | 61 72 7b 73 75 66 66 69 |code{(\v|ar{suffi|
|00000230| 78 7d 2c 20 5c 76 61 72 | 7b 6d 6f 64 65 7d 2c 0d |x}, \var|{mode},.|
|00000240| 5c 76 61 72 7b 74 79 70 | 65 7d 29 7d 2c 20 77 68 |\var{typ|e})}, wh|
|00000250| 65 72 65 20 5c 76 61 72 | 7b 73 75 66 66 69 78 7d |ere \var|{suffix}|
|00000260| 20 69 73 20 61 20 73 74 | 72 69 6e 67 20 74 6f 20 | is a st|ring to |
|00000270| 62 65 20 61 70 70 65 6e | 64 65 64 20 74 6f 20 74 |be appen|ded to t|
|00000280| 68 65 0d 6d 6f 64 75 6c | 65 20 6e 61 6d 65 20 74 |he.modul|e name t|
|00000290| 6f 20 66 6f 72 6d 20 74 | 68 65 20 66 69 6c 65 6e |o form t|he filen|
|000002a0| 61 6d 65 20 74 6f 20 73 | 65 61 72 63 68 20 66 6f |ame to s|earch fo|
|000002b0| 72 2c 20 5c 76 61 72 7b | 6d 6f 64 65 7d 20 69 73 |r, \var{|mode} is|
|000002c0| 20 74 68 65 20 6d 6f 64 | 65 0d 73 74 72 69 6e 67 | the mod|e.string|
|000002d0| 20 74 6f 20 70 61 73 73 | 20 74 6f 20 74 68 65 20 | to pass| to the |
|000002e0| 62 75 69 6c 74 2d 69 6e | 20 5c 63 6f 64 65 7b 6f |built-in| \code{o|
|000002f0| 70 65 6e 7d 20 66 75 6e | 63 74 69 6f 6e 20 74 6f |pen} fun|ction to|
|00000300| 20 6f 70 65 6e 20 74 68 | 65 20 66 69 6c 65 0d 28 | open th|e file.(|
|00000310| 74 68 69 73 20 63 61 6e | 20 62 65 20 5c 63 6f 64 |this can| be \cod|
|00000320| 65 7b 27 72 27 7d 20 66 | 6f 72 20 74 65 78 74 20 |e{'r'} f|or text |
|00000330| 66 69 6c 65 73 20 6f 72 | 20 5c 63 6f 64 65 7b 27 |files or| \code{'|
|00000340| 72 62 27 7d 20 66 6f 72 | 20 62 69 6e 61 72 79 0d |rb'} for| binary.|
|00000350| 66 69 6c 65 73 29 2c 20 | 61 6e 64 20 5c 76 61 72 |files), |and \var|
|00000360| 7b 74 79 70 65 7d 20 69 | 73 20 74 68 65 20 66 69 |{type} i|s the fi|
|00000370| 6c 65 20 74 79 70 65 2c | 20 77 68 69 63 68 20 68 |le type,| which h|
|00000380| 61 73 20 6f 6e 65 20 6f | 66 20 74 68 65 20 76 61 |as one o|f the va|
|00000390| 6c 75 65 73 0d 5c 63 6f | 64 65 7b 50 59 5f 53 4f |lues.\co|de{PY_SO|
|000003a0| 55 52 43 45 7d 2c 20 5c | 63 6f 64 65 7b 50 59 5f |URCE}, \|code{PY_|
|000003b0| 43 4f 4d 50 49 4c 45 44 | 7d 20 6f 72 20 5c 63 6f |COMPILED|} or \co|
|000003c0| 64 65 7b 43 5f 45 58 54 | 45 4e 53 49 4f 4e 7d 2c |de{C_EXT|ENSION},|
|000003d0| 20 64 65 66 69 6e 65 64 | 0d 62 65 6c 6f 77 2e 20 | defined|.below. |
|000003e0| 20 28 53 79 73 74 65 6d | 2d 64 65 70 65 6e 64 65 | (System|-depende|
|000003f0| 6e 74 20 76 61 6c 75 65 | 73 20 6d 61 79 20 61 6c |nt value|s may al|
|00000400| 73 6f 20 62 65 20 72 65 | 74 75 72 6e 65 64 2e 29 |so be re|turned.)|
|00000410| 0d 5c 65 6e 64 7b 66 75 | 6e 63 64 65 73 63 7d 0d |.\end{fu|ncdesc}.|
|00000420| 0d 5c 62 65 67 69 6e 7b | 66 75 6e 63 64 65 73 63 |.\begin{|funcdesc|
|00000430| 7d 7b 66 69 6e 64 5f 6d | 6f 64 75 6c 65 7d 7b 6e |}{find_m|odule}{n|
|00000440| 61 6d 65 5c 2c 20 5c 6f | 70 74 69 6f 6e 61 6c 7b |ame\, \o|ptional{|
|00000450| 70 61 74 68 7d 7d 0d 54 | 72 79 20 74 6f 20 66 69 |path}}.T|ry to fi|
|00000460| 6e 64 20 74 68 65 20 6d | 6f 64 75 6c 65 20 5c 76 |nd the m|odule \v|
|00000470| 61 72 7b 6e 61 6d 65 7d | 20 6f 6e 20 74 68 65 20 |ar{name}| on the |
|00000480| 73 65 61 72 63 68 20 70 | 61 74 68 20 5c 76 61 72 |search p|ath \var|
|00000490| 7b 70 61 74 68 7d 2e 20 | 20 54 68 65 0d 64 65 66 |{path}. | The.def|
|000004a0| 61 75 6c 74 20 5c 76 61 | 72 7b 70 61 74 68 7d 20 |ault \va|r{path} |
|000004b0| 69 73 20 5c 63 6f 64 65 | 7b 73 79 73 2e 70 61 74 |is \code|{sys.pat|
|000004c0| 68 7d 2e 20 20 54 68 65 | 20 72 65 74 75 72 6e 20 |h}. The| return |
|000004d0| 76 61 6c 75 65 20 69 73 | 20 61 20 74 72 69 70 6c |value is| a tripl|
|000004e0| 65 0d 5c 63 6f 64 65 7b | 28 5c 76 61 72 7b 66 69 |e.\code{|(\var{fi|
|000004f0| 6c 65 7d 2c 20 5c 76 61 | 72 7b 70 61 74 68 6e 61 |le}, \va|r{pathna|
|00000500| 6d 65 7d 2c 20 5c 76 61 | 72 7b 64 65 73 63 72 69 |me}, \va|r{descri|
|00000510| 70 74 69 6f 6e 7d 29 7d | 20 77 68 65 72 65 0d 5c |ption})}| where.\|
|00000520| 76 61 72 7b 66 69 6c 65 | 7d 20 69 73 20 61 6e 20 |var{file|} is an |
|00000530| 6f 70 65 6e 20 66 69 6c | 65 20 6f 62 6a 65 63 74 |open fil|e object|
|00000540| 20 70 6f 73 69 74 69 6f | 6e 65 64 20 61 74 20 74 | positio|ned at t|
|00000550| 68 65 20 62 65 67 69 6e | 6e 69 6e 67 2c 0d 5c 76 |he begin|ning,.\v|
|00000560| 61 72 7b 70 61 74 68 6e | 61 6d 65 7d 20 69 73 20 |ar{pathn|ame} is |
|00000570| 74 68 65 20 70 61 74 68 | 6e 61 6d 65 20 6f 66 20 |the path|name of |
|00000580| 74 68 65 0d 66 69 6c 65 | 20 66 6f 75 6e 64 2c 20 |the.file| found, |
|00000590| 61 6e 64 20 5c 76 61 72 | 7b 64 65 73 63 72 69 70 |and \var|{descrip|
|000005a0| 74 69 6f 6e 7d 20 69 73 | 20 61 20 74 72 69 70 6c |tion} is| a tripl|
|000005b0| 65 20 61 73 20 63 6f 6e | 74 61 69 6e 65 64 20 69 |e as con|tained i|
|000005c0| 6e 20 74 68 65 20 6c 69 | 73 74 0d 72 65 74 75 72 |n the li|st.retur|
|000005d0| 6e 65 64 20 62 79 20 5c | 63 6f 64 65 7b 67 65 74 |ned by \|code{get|
|000005e0| 5f 73 75 66 66 69 78 65 | 73 7d 20 64 65 73 63 72 |_suffixe|s} descr|
|000005f0| 69 62 69 6e 67 20 74 68 | 65 20 6b 69 6e 64 20 6f |ibing th|e kind o|
|00000600| 66 20 66 69 6c 65 20 66 | 6f 75 6e 64 2e 0d 5c 65 |f file f|ound..\e|
|00000610| 6e 64 7b 66 75 6e 63 64 | 65 73 63 7d 0d 0d 5c 62 |nd{funcd|esc}..\b|
|00000620| 65 67 69 6e 7b 66 75 6e | 63 64 65 73 63 7d 7b 69 |egin{fun|cdesc}{i|
|00000630| 6e 69 74 5f 62 75 69 6c | 74 69 6e 7d 7b 6e 61 6d |nit_buil|tin}{nam|
|00000640| 65 7d 0d 49 6e 69 74 69 | 61 6c 69 7a 65 20 74 68 |e}.Initi|alize th|
|00000650| 65 20 62 75 69 6c 74 2d | 69 6e 20 6d 6f 64 75 6c |e built-|in modul|
|00000660| 65 20 63 61 6c 6c 65 64 | 20 5c 76 61 72 7b 6e 61 |e called| \var{na|
|00000670| 6d 65 7d 20 61 6e 64 20 | 72 65 74 75 72 6e 20 69 |me} and |return i|
|00000680| 74 73 20 6d 6f 64 75 6c | 65 0d 6f 62 6a 65 63 74 |ts modul|e.object|
|00000690| 2e 20 20 49 66 20 74 68 | 65 20 6d 6f 64 75 6c 65 |. If th|e module|
|000006a0| 20 77 61 73 20 61 6c 72 | 65 61 64 79 20 69 6e 69 | was alr|eady ini|
|000006b0| 74 69 61 6c 69 7a 65 64 | 2c 20 69 74 20 77 69 6c |tialized|, it wil|
|000006c0| 6c 20 62 65 20 69 6e 69 | 74 69 61 6c 69 7a 65 64 |l be ini|tialized|
|000006d0| 0d 7b 5c 65 6d 20 61 67 | 61 69 6e 7d 2e 20 20 41 |.{\em ag|ain}. A|
|000006e0| 20 66 65 77 20 6d 6f 64 | 75 6c 65 73 20 63 61 6e | few mod|ules can|
|000006f0| 6e 6f 74 20 62 65 20 69 | 6e 69 74 69 61 6c 69 7a |not be i|nitializ|
|00000700| 65 64 20 74 77 69 63 65 | 20 2d 2d 2d 20 61 74 74 |ed twice| --- att|
|00000710| 65 6d 70 74 69 6e 67 0d | 74 6f 20 69 6e 69 74 69 |empting.|to initi|
|00000720| 61 6c 69 7a 65 20 74 68 | 65 73 65 20 61 67 61 69 |alize th|ese agai|
|00000730| 6e 20 77 69 6c 6c 20 72 | 61 69 73 65 20 61 6e 20 |n will r|aise an |
|00000740| 5c 63 6f 64 65 7b 49 6d | 70 6f 72 74 45 72 72 6f |\code{Im|portErro|
|00000750| 72 7d 20 65 78 63 65 70 | 74 69 6f 6e 2e 0d 49 66 |r} excep|tion..If|
|00000760| 20 74 68 65 72 65 20 69 | 73 20 6e 6f 0d 62 75 69 | there i|s no.bui|
|00000770| 6c 74 2d 69 6e 20 6d 6f | 64 75 6c 65 20 63 61 6c |lt-in mo|dule cal|
|00000780| 6c 65 64 20 5c 76 61 72 | 7b 6e 61 6d 65 7d 2c 20 |led \var|{name}, |
|00000790| 5c 63 6f 64 65 7b 4e 6f | 6e 65 7d 20 69 73 20 72 |\code{No|ne} is r|
|000007a0| 65 74 75 72 6e 65 64 2e | 0d 5c 65 6e 64 7b 66 75 |eturned.|.\end{fu|
|000007b0| 6e 63 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |ncdesc}.|.\begin{|
|000007c0| 66 75 6e 63 64 65 73 63 | 7d 7b 69 6e 69 74 5f 66 |funcdesc|}{init_f|
|000007d0| 72 6f 7a 65 6e 7d 7b 6e | 61 6d 65 7d 0d 49 6e 69 |rozen}{n|ame}.Ini|
|000007e0| 74 69 61 6c 69 7a 65 20 | 74 68 65 20 66 72 6f 7a |tialize |the froz|
|000007f0| 65 6e 20 6d 6f 64 75 6c | 65 20 63 61 6c 6c 65 64 |en modul|e called|
|00000800| 20 5c 76 61 72 7b 6e 61 | 6d 65 7d 20 61 6e 64 20 | \var{na|me} and |
|00000810| 72 65 74 75 72 6e 20 69 | 74 73 20 6d 6f 64 75 6c |return i|ts modul|
|00000820| 65 0d 6f 62 6a 65 63 74 | 2e 20 20 49 66 20 74 68 |e.object|. If th|
|00000830| 65 20 6d 6f 64 75 6c 65 | 20 77 61 73 20 61 6c 72 |e module| was alr|
|00000840| 65 61 64 79 20 69 6e 69 | 74 69 61 6c 69 7a 65 64 |eady ini|tialized|
|00000850| 2c 20 69 74 20 77 69 6c | 6c 20 62 65 20 69 6e 69 |, it wil|l be ini|
|00000860| 74 69 61 6c 69 7a 65 64 | 0d 7b 5c 65 6d 20 61 67 |tialized|.{\em ag|
|00000870| 61 69 6e 7d 2e 20 20 49 | 66 20 74 68 65 72 65 20 |ain}. I|f there |
|00000880| 69 73 20 6e 6f 20 66 72 | 6f 7a 65 6e 20 6d 6f 64 |is no fr|ozen mod|
|00000890| 75 6c 65 20 63 61 6c 6c | 65 64 20 5c 76 61 72 7b |ule call|ed \var{|
|000008a0| 6e 61 6d 65 7d 2c 0d 5c | 63 6f 64 65 7b 4e 6f 6e |name},.\|code{Non|
|000008b0| 65 7d 20 69 73 20 72 65 | 74 75 72 6e 65 64 2e 20 |e} is re|turned. |
|000008c0| 20 28 46 72 6f 7a 65 6e | 20 6d 6f 64 75 6c 65 73 | (Frozen| modules|
|000008d0| 20 61 72 65 20 6d 6f 64 | 75 6c 65 73 20 77 72 69 | are mod|ules wri|
|000008e0| 74 74 65 6e 20 69 6e 0d | 50 79 74 68 6f 6e 20 77 |tten in.|Python w|
|000008f0| 68 6f 73 65 20 63 6f 6d | 70 69 6c 65 64 20 62 79 |hose com|piled by|
|00000900| 74 65 2d 63 6f 64 65 20 | 6f 62 6a 65 63 74 20 69 |te-code |object i|
|00000910| 73 20 69 6e 63 6f 72 70 | 6f 72 61 74 65 64 20 69 |s incorp|orated i|
|00000920| 6e 74 6f 20 61 0d 63 75 | 73 74 6f 6d 2d 62 75 69 |nto a.cu|stom-bui|
|00000930| 6c 74 20 50 79 74 68 6f | 6e 20 69 6e 74 65 72 70 |lt Pytho|n interp|
|00000940| 72 65 74 65 72 20 62 79 | 20 50 79 74 68 6f 6e 27 |reter by| Python'|
|00000950| 73 20 5c 63 6f 64 65 7b | 66 72 65 65 7a 65 7d 20 |s \code{|freeze} |
|00000960| 75 74 69 6c 69 74 79 2e | 0d 53 65 65 20 5c 63 6f |utility.|.See \co|
|00000970| 64 65 7b 54 6f 6f 6c 73 | 2f 66 72 65 65 7a 65 7d |de{Tools|/freeze}|
|00000980| 20 66 6f 72 20 6e 6f 77 | 2e 29 0d 5c 65 6e 64 7b | for now|.).\end{|
|00000990| 66 75 6e 63 64 65 73 63 | 7d 0d 0d 5c 62 65 67 69 |funcdesc|}..\begi|
|000009a0| 6e 7b 66 75 6e 63 64 65 | 73 63 7d 7b 69 73 5f 62 |n{funcde|sc}{is_b|
|000009b0| 75 69 6c 74 69 6e 7d 7b | 6e 61 6d 65 7d 0d 52 65 |uiltin}{|name}.Re|
|000009c0| 74 75 72 6e 20 5c 63 6f | 64 65 7b 31 7d 20 69 66 |turn \co|de{1} if|
|000009d0| 20 74 68 65 72 65 20 69 | 73 20 61 20 62 75 69 6c | there i|s a buil|
|000009e0| 74 2d 69 6e 20 6d 6f 64 | 75 6c 65 20 63 61 6c 6c |t-in mod|ule call|
|000009f0| 65 64 20 5c 76 61 72 7b | 6e 61 6d 65 7d 20 77 68 |ed \var{|name} wh|
|00000a00| 69 63 68 20 63 61 6e 20 | 62 65 0d 69 6e 69 74 69 |ich can |be.initi|
|00000a10| 61 6c 69 7a 65 64 20 61 | 67 61 69 6e 2e 20 20 52 |alized a|gain. R|
|00000a20| 65 74 75 72 6e 20 5c 63 | 6f 64 65 7b 2d 31 7d 20 |eturn \c|ode{-1} |
|00000a30| 69 66 20 74 68 65 72 65 | 20 69 73 20 61 20 62 75 |if there| is a bu|
|00000a40| 69 6c 74 2d 69 6e 20 6d | 6f 64 75 6c 65 0d 63 61 |ilt-in m|odule.ca|
|00000a50| 6c 6c 65 64 20 5c 76 61 | 72 7b 6e 61 6d 65 7d 20 |lled \va|r{name} |
|00000a60| 77 68 69 63 68 20 63 61 | 6e 6e 6f 74 20 62 65 20 |which ca|nnot be |
|00000a70| 69 6e 69 74 69 61 6c 69 | 7a 65 64 20 61 67 61 69 |initiali|zed agai|
|00000a80| 6e 20 28 73 65 65 0d 5c | 63 6f 64 65 7b 69 6e 69 |n (see.\|code{ini|
|00000a90| 74 5f 62 75 69 6c 74 69 | 6e 7d 29 2e 20 20 52 65 |t_builti|n}). Re|
|00000aa0| 74 75 72 6e 20 5c 63 6f | 64 65 7b 30 7d 20 69 66 |turn \co|de{0} if|
|00000ab0| 20 74 68 65 72 65 20 69 | 73 20 6e 6f 20 62 75 69 | there i|s no bui|
|00000ac0| 6c 74 2d 69 6e 20 6d 6f | 64 75 6c 65 0d 63 61 6c |lt-in mo|dule.cal|
|00000ad0| 6c 65 64 20 5c 76 61 72 | 7b 6e 61 6d 65 7d 2e 0d |led \var|{name}..|
|00000ae0| 5c 65 6e 64 7b 66 75 6e | 63 64 65 73 63 7d 0d 0d |\end{fun|cdesc}..|
|00000af0| 5c 62 65 67 69 6e 7b 66 | 75 6e 63 64 65 73 63 7d |\begin{f|uncdesc}|
|00000b00| 7b 69 73 5f 66 72 6f 7a | 65 6e 7d 7b 6e 61 6d 65 |{is_froz|en}{name|
|00000b10| 7d 0d 52 65 74 75 72 6e | 20 5c 63 6f 64 65 7b 31 |}.Return| \code{1|
|00000b20| 7d 20 69 66 20 74 68 65 | 72 65 20 69 73 20 61 20 |} if the|re is a |
|00000b30| 66 72 6f 7a 65 6e 20 6d | 6f 64 75 6c 65 20 28 73 |frozen m|odule (s|
|00000b40| 65 65 20 5c 63 6f 64 65 | 7b 69 6e 69 74 5f 66 72 |ee \code|{init_fr|
|00000b50| 6f 7a 65 6e 7d 29 0d 63 | 61 6c 6c 65 64 20 5c 76 |ozen}).c|alled \v|
|00000b60| 61 72 7b 6e 61 6d 65 7d | 2c 20 5c 63 6f 64 65 7b |ar{name}|, \code{|
|00000b70| 30 7d 20 69 66 20 74 68 | 65 72 65 20 69 73 20 6e |0} if th|ere is n|
|00000b80| 6f 20 73 75 63 68 20 6d | 6f 64 75 6c 65 2e 0d 5c |o such m|odule..\|
|00000b90| 65 6e 64 7b 66 75 6e 63 | 64 65 73 63 7d 0d 0d 5c |end{func|desc}..\|
|00000ba0| 62 65 67 69 6e 7b 66 75 | 6e 63 64 65 73 63 7d 7b |begin{fu|ncdesc}{|
|00000bb0| 6c 6f 61 64 5f 63 6f 6d | 70 69 6c 65 64 7d 7b 6e |load_com|piled}{n|
|00000bc0| 61 6d 65 5c 2c 20 70 61 | 74 68 6e 61 6d 65 5c 2c |ame\, pa|thname\,|
|00000bd0| 20 5c 6f 70 74 69 6f 6e | 61 6c 7b 66 69 6c 65 7d | \option|al{file}|
|00000be0| 7d 0d 4c 6f 61 64 20 61 | 6e 64 20 69 6e 69 74 69 |}.Load a|nd initi|
|00000bf0| 61 6c 69 7a 65 20 61 20 | 6d 6f 64 75 6c 65 20 69 |alize a |module i|
|00000c00| 6d 70 6c 65 6d 65 6e 74 | 65 64 20 61 73 20 61 20 |mplement|ed as a |
|00000c10| 62 79 74 65 2d 63 6f 6d | 70 69 6c 65 64 20 63 6f |byte-com|piled co|
|00000c20| 64 65 20 66 69 6c 65 0d | 61 6e 64 20 72 65 74 75 |de file.|and retu|
|00000c30| 72 6e 20 69 74 73 20 6d | 6f 64 75 6c 65 20 6f 62 |rn its m|odule ob|
|00000c40| 6a 65 63 74 2e 20 20 49 | 66 20 74 68 65 20 6d 6f |ject. I|f the mo|
|00000c50| 64 75 6c 65 20 77 61 73 | 20 61 6c 72 65 61 64 79 |dule was| already|
|00000c60| 20 69 6e 69 74 69 61 6c | 69 7a 65 64 2c 0d 69 74 | initial|ized,.it|
|00000c70| 20 77 69 6c 6c 20 62 65 | 20 69 6e 69 74 69 61 6c | will be| initial|
|00000c80| 69 7a 65 64 20 7b 5c 65 | 6d 20 61 67 61 69 6e 7d |ized {\e|m again}|
|00000c90| 2e 20 20 54 68 65 20 5c | 76 61 72 7b 6e 61 6d 65 |. The \|var{name|
|00000ca0| 7d 20 61 72 67 75 6d 65 | 6e 74 20 69 73 20 75 73 |} argume|nt is us|
|00000cb0| 65 64 0d 74 6f 20 63 72 | 65 61 74 65 20 6f 72 20 |ed.to cr|eate or |
|00000cc0| 61 63 63 65 73 73 20 61 | 20 6d 6f 64 75 6c 65 20 |access a| module |
|00000cd0| 6f 62 6a 65 63 74 2e 20 | 20 54 68 65 20 5c 76 61 |object. | The \va|
|00000ce0| 72 7b 70 61 74 68 6e 61 | 6d 65 7d 20 61 72 67 75 |r{pathna|me} argu|
|00000cf0| 6d 65 6e 74 0d 70 6f 69 | 6e 74 73 20 74 6f 20 74 |ment.poi|nts to t|
|00000d00| 68 65 20 62 79 74 65 2d | 63 6f 6d 70 69 6c 65 64 |he byte-|compiled|
|00000d10| 20 63 6f 64 65 20 66 69 | 6c 65 2e 20 20 54 68 65 | code fi|le. The|
|00000d20| 20 6f 70 74 69 6f 6e 61 | 6c 20 5c 76 61 72 7b 66 | optiona|l \var{f|
|00000d30| 69 6c 65 7d 0d 61 72 67 | 75 6d 65 6e 74 20 69 73 |ile}.arg|ument is|
|00000d40| 20 74 68 65 20 62 79 74 | 65 2d 63 6f 6d 70 69 6c | the byt|e-compil|
|00000d50| 65 64 20 63 6f 64 65 20 | 66 69 6c 65 2c 20 6f 70 |ed code |file, op|
|00000d60| 65 6e 20 66 6f 72 20 72 | 65 61 64 69 6e 67 20 69 |en for r|eading i|
|00000d70| 6e 20 62 69 6e 61 72 79 | 0d 6d 6f 64 65 2c 20 66 |n binary|.mode, f|
|00000d80| 72 6f 6d 20 74 68 65 20 | 62 65 67 69 6e 6e 69 6e |rom the |beginnin|
|00000d90| 67 20 2d 2d 2d 20 69 66 | 20 6e 6f 74 20 67 69 76 |g --- if| not giv|
|00000da0| 65 6e 2c 20 74 68 65 20 | 66 75 6e 63 74 69 6f 6e |en, the |function|
|00000db0| 20 6f 70 65 6e 73 0d 5c | 76 61 72 7b 70 61 74 68 | opens.\|var{path|
|00000dc0| 6e 61 6d 65 7d 2e 20 20 | 49 74 20 6d 75 73 74 20 |name}. |It must |
|00000dd0| 63 75 72 72 65 6e 74 6c | 79 20 62 65 20 61 20 72 |currentl|y be a r|
|00000de0| 65 61 6c 20 66 69 6c 65 | 20 6f 62 6a 65 63 74 2c |eal file| object,|
|00000df0| 20 6e 6f 74 20 61 0d 75 | 73 65 72 2d 64 65 66 69 | not a.u|ser-defi|
|00000e00| 6e 65 64 20 63 6c 61 73 | 73 20 65 6d 75 6c 61 74 |ned clas|s emulat|
|00000e10| 69 6e 67 20 61 20 66 69 | 6c 65 2e 0d 5c 65 6e 64 |ing a fi|le..\end|
|00000e20| 7b 66 75 6e 63 64 65 73 | 63 7d 0d 0d 5c 62 65 67 |{funcdes|c}..\beg|
|00000e30| 69 6e 7b 66 75 6e 63 64 | 65 73 63 7d 7b 6c 6f 61 |in{funcd|esc}{loa|
|00000e40| 64 5f 64 79 6e 61 6d 69 | 63 7d 7b 6e 61 6d 65 5c |d_dynami|c}{name\|
|00000e50| 2c 20 70 61 74 68 6e 61 | 6d 65 5c 2c 20 5c 6f 70 |, pathna|me\, \op|
|00000e60| 74 69 6f 6e 61 6c 7b 66 | 69 6c 65 7d 7d 0d 4c 6f |tional{f|ile}}.Lo|
|00000e70| 61 64 20 61 6e 64 20 69 | 6e 69 74 69 61 6c 69 7a |ad and i|nitializ|
|00000e80| 65 20 61 20 6d 6f 64 75 | 6c 65 20 69 6d 70 6c 65 |e a modu|le imple|
|00000e90| 6d 65 6e 74 65 64 20 61 | 73 20 61 20 64 79 6e 61 |mented a|s a dyna|
|00000ea0| 6d 69 63 61 6c 6c 79 20 | 6c 6f 61 64 61 62 6c 65 |mically |loadable|
|00000eb0| 0d 73 68 61 72 65 64 20 | 6c 69 62 72 61 72 79 20 |.shared |library |
|00000ec0| 61 6e 64 20 72 65 74 75 | 72 6e 20 69 74 73 20 6d |and retu|rn its m|
|00000ed0| 6f 64 75 6c 65 20 6f 62 | 6a 65 63 74 2e 20 20 49 |odule ob|ject. I|
|00000ee0| 66 20 74 68 65 20 6d 6f | 64 75 6c 65 20 77 61 73 |f the mo|dule was|
|00000ef0| 0d 61 6c 72 65 61 64 79 | 20 69 6e 69 74 69 61 6c |.already| initial|
|00000f00| 69 7a 65 64 2c 20 69 74 | 20 77 69 6c 6c 20 62 65 |ized, it| will be|
|00000f10| 20 69 6e 69 74 69 61 6c | 69 7a 65 64 20 7b 5c 65 | initial|ized {\e|
|00000f20| 6d 20 61 67 61 69 6e 7d | 2e 20 20 53 6f 6d 65 20 |m again}|. Some |
|00000f30| 6d 6f 64 75 6c 65 73 0d | 64 6f 6e 27 74 20 6c 69 |modules.|don't li|
|00000f40| 6b 65 20 74 68 61 74 20 | 61 6e 64 20 6d 61 79 20 |ke that |and may |
|00000f50| 72 61 69 73 65 20 61 6e | 20 65 78 63 65 70 74 69 |raise an| excepti|
|00000f60| 6f 6e 2e 20 20 54 68 65 | 20 5c 76 61 72 7b 70 61 |on. The| \var{pa|
|00000f70| 74 68 6e 61 6d 65 7d 0d | 61 72 67 75 6d 65 6e 74 |thname}.|argument|
|00000f80| 20 6d 75 73 74 20 70 6f | 69 6e 74 20 74 6f 20 74 | must po|int to t|
|00000f90| 68 65 20 73 68 61 72 65 | 64 20 6c 69 62 72 61 72 |he share|d librar|
|00000fa0| 79 2e 20 20 54 68 65 20 | 5c 76 61 72 7b 6e 61 6d |y. The |\var{nam|
|00000fb0| 65 7d 20 61 72 67 75 6d | 65 6e 74 20 69 73 0d 75 |e} argum|ent is.u|
|00000fc0| 73 65 64 20 74 6f 20 63 | 6f 6e 73 74 72 75 63 74 |sed to c|onstruct|
|00000fd0| 20 74 68 65 20 6e 61 6d | 65 20 6f 66 20 74 68 65 | the nam|e of the|
|00000fe0| 20 69 6e 69 74 69 61 6c | 69 7a 61 74 69 6f 6e 20 | initial|ization |
|00000ff0| 66 75 6e 63 74 69 6f 6e | 3a 20 61 6e 20 65 78 74 |function|: an ext|
|00001000| 65 72 6e 61 6c 0d 43 20 | 66 75 6e 63 74 69 6f 6e |ernal.C |function|
|00001010| 20 63 61 6c 6c 65 64 20 | 5c 63 6f 64 65 7b 69 6e | called |\code{in|
|00001020| 69 74 5c 76 61 72 7b 6e | 61 6d 65 7d 28 29 7d 20 |it\var{n|ame}()} |
|00001030| 69 6e 20 74 68 65 20 73 | 68 61 72 65 64 20 6c 69 |in the s|hared li|
|00001040| 62 72 61 72 79 20 69 73 | 0d 63 61 6c 6c 65 64 2e |brary is|.called.|
|00001050| 20 20 54 68 65 20 6f 70 | 74 69 6f 6e 61 6c 20 5c | The op|tional \|
|00001060| 76 61 72 7b 66 69 6c 65 | 7d 20 61 72 67 6d 65 6e |var{file|} argmen|
|00001070| 74 20 69 73 20 69 67 6e | 6f 72 65 64 2e 20 20 28 |t is ign|ored. (|
|00001080| 4e 6f 74 65 3a 20 75 73 | 69 6e 67 0d 73 68 61 72 |Note: us|ing.shar|
|00001090| 65 64 20 6c 69 62 72 61 | 72 69 65 73 20 69 73 20 |ed libra|ries is |
|000010a0| 68 69 67 68 6c 79 20 73 | 79 73 74 65 6d 20 64 65 |highly s|ystem de|
|000010b0| 70 65 6e 64 65 6e 74 2c | 20 61 6e 64 20 6e 6f 74 |pendent,| and not|
|000010c0| 20 61 6c 6c 20 73 79 73 | 74 65 6d 73 0d 73 75 70 | all sys|tems.sup|
|000010d0| 70 6f 72 74 20 69 74 2e | 29 0d 5c 65 6e 64 7b 66 |port it.|).\end{f|
|000010e0| 75 6e 63 64 65 73 63 7d | 0d 0d 5c 62 65 67 69 6e |uncdesc}|..\begin|
|000010f0| 7b 66 75 6e 63 64 65 73 | 63 7d 7b 6c 6f 61 64 5f |{funcdes|c}{load_|
|00001100| 73 6f 75 72 63 65 7d 7b | 6e 61 6d 65 5c 2c 20 70 |source}{|name\, p|
|00001110| 61 74 68 6e 61 6d 65 5c | 2c 20 5c 6f 70 74 69 6f |athname\|, \optio|
|00001120| 6e 61 6c 7b 66 69 6c 65 | 7d 7d 0d 4c 6f 61 64 20 |nal{file|}}.Load |
|00001130| 61 6e 64 20 69 6e 69 74 | 69 61 6c 69 7a 65 20 61 |and init|ialize a|
|00001140| 20 6d 6f 64 75 6c 65 20 | 69 6d 70 6c 65 6d 65 6e | module |implemen|
|00001150| 74 65 64 20 61 73 20 61 | 20 50 79 74 68 6f 6e 20 |ted as a| Python |
|00001160| 73 6f 75 72 63 65 20 66 | 69 6c 65 20 61 6e 64 0d |source f|ile and.|
|00001170| 72 65 74 75 72 6e 20 69 | 74 73 20 6d 6f 64 75 6c |return i|ts modul|
|00001180| 65 20 6f 62 6a 65 63 74 | 2e 20 20 49 66 20 74 68 |e object|. If th|
|00001190| 65 20 6d 6f 64 75 6c 65 | 20 77 61 73 20 61 6c 72 |e module| was alr|
|000011a0| 65 61 64 79 20 69 6e 69 | 74 69 61 6c 69 7a 65 64 |eady ini|tialized|
|000011b0| 2c 20 69 74 0d 77 69 6c | 6c 20 62 65 20 69 6e 69 |, it.wil|l be ini|
|000011c0| 74 69 61 6c 69 7a 65 64 | 20 7b 5c 65 6d 20 61 67 |tialized| {\em ag|
|000011d0| 61 69 6e 7d 2e 20 20 54 | 68 65 20 5c 76 61 72 7b |ain}. T|he \var{|
|000011e0| 6e 61 6d 65 7d 20 61 72 | 67 75 6d 65 6e 74 20 69 |name} ar|gument i|
|000011f0| 73 20 75 73 65 64 20 74 | 6f 0d 63 72 65 61 74 65 |s used t|o.create|
|00001200| 20 6f 72 20 61 63 63 65 | 73 73 20 61 20 6d 6f 64 | or acce|ss a mod|
|00001210| 75 6c 65 20 6f 62 6a 65 | 63 74 2e 20 20 54 68 65 |ule obje|ct. The|
|00001220| 20 5c 76 61 72 7b 70 61 | 74 68 6e 61 6d 65 7d 20 | \var{pa|thname} |
|00001230| 61 72 67 75 6d 65 6e 74 | 20 70 6f 69 6e 74 73 0d |argument| points.|
|00001240| 74 6f 20 74 68 65 20 73 | 6f 75 72 63 65 20 66 69 |to the s|ource fi|
|00001250| 6c 65 2e 20 20 54 68 65 | 20 6f 70 74 69 6f 6e 61 |le. The| optiona|
|00001260| 6c 20 5c 76 61 72 7b 66 | 69 6c 65 7d 20 61 72 67 |l \var{f|ile} arg|
|00001270| 75 6d 65 6e 74 20 69 73 | 20 74 68 65 20 73 6f 75 |ument is| the sou|
|00001280| 72 63 65 0d 66 69 6c 65 | 2c 20 6f 70 65 6e 20 66 |rce.file|, open f|
|00001290| 6f 72 20 72 65 61 64 69 | 6e 67 20 61 73 20 74 65 |or readi|ng as te|
|000012a0| 78 74 2c 20 66 72 6f 6d | 20 74 68 65 20 62 65 67 |xt, from| the beg|
|000012b0| 69 6e 6e 69 6e 67 20 2d | 2d 2d 20 69 66 20 6e 6f |inning -|-- if no|
|000012c0| 74 20 67 69 76 65 6e 2c | 0d 74 68 65 20 66 75 6e |t given,|.the fun|
|000012d0| 63 74 69 6f 6e 20 6f 70 | 65 6e 73 20 5c 76 61 72 |ction op|ens \var|
|000012e0| 7b 70 61 74 68 6e 61 6d | 65 7d 2e 20 20 49 74 20 |{pathnam|e}. It |
|000012f0| 6d 75 73 74 20 63 75 72 | 72 65 6e 74 6c 79 20 62 |must cur|rently b|
|00001300| 65 20 61 20 72 65 61 6c | 20 66 69 6c 65 0d 6f 62 |e a real| file.ob|
|00001310| 6a 65 63 74 2c 20 6e 6f | 74 20 61 20 75 73 65 72 |ject, no|t a user|
|00001320| 2d 64 65 66 69 6e 65 64 | 20 63 6c 61 73 73 20 65 |-defined| class e|
|00001330| 6d 75 6c 61 74 69 6e 67 | 20 61 20 66 69 6c 65 2e |mulating| a file.|
|00001340| 20 20 4e 6f 74 65 20 74 | 68 61 74 20 69 66 20 61 | Note t|hat if a|
|00001350| 0d 70 72 6f 70 65 72 6c | 79 20 6d 61 74 63 68 69 |.properl|y matchi|
|00001360| 6e 67 20 62 79 74 65 2d | 63 6f 6d 70 69 6c 65 64 |ng byte-|compiled|
|00001370| 20 66 69 6c 65 20 28 77 | 69 74 68 20 73 75 66 66 | file (w|ith suff|
|00001380| 69 78 20 5c 63 6f 64 65 | 7b 2e 70 79 63 7d 29 20 |ix \code|{.pyc}) |
|00001390| 65 78 69 73 74 73 2c 0d | 69 74 20 77 69 6c 6c 20 |exists,.|it will |
|000013a0| 62 65 20 75 73 65 64 20 | 69 6e 73 74 65 61 64 20 |be used |instead |
|000013b0| 6f 66 20 70 61 72 73 69 | 6e 67 20 74 68 65 20 67 |of parsi|ng the g|
|000013c0| 69 76 65 6e 20 73 6f 75 | 72 63 65 20 66 69 6c 65 |iven sou|rce file|
|000013d0| 2e 0d 5c 65 6e 64 7b 66 | 75 6e 63 64 65 73 63 7d |..\end{f|uncdesc}|
|000013e0| 0d 0d 5c 62 65 67 69 6e | 7b 66 75 6e 63 64 65 73 |..\begin|{funcdes|
|000013f0| 63 7d 7b 6e 65 77 5f 6d | 6f 64 75 6c 65 7d 7b 6e |c}{new_m|odule}{n|
|00001400| 61 6d 65 7d 0d 52 65 74 | 75 72 6e 20 61 20 6e 65 |ame}.Ret|urn a ne|
|00001410| 77 20 65 6d 70 74 79 20 | 6d 6f 64 75 6c 65 20 6f |w empty |module o|
|00001420| 62 6a 65 63 74 20 63 61 | 6c 6c 65 64 20 5c 76 61 |bject ca|lled \va|
|00001430| 72 7b 6e 61 6d 65 7d 2e | 20 20 54 68 69 73 20 6f |r{name}.| This o|
|00001440| 62 6a 65 63 74 20 69 73 | 0d 7b 5c 65 6d 20 6e 6f |bject is|.{\em no|
|00001450| 74 7d 20 69 6e 73 65 72 | 74 65 64 20 69 6e 20 5c |t} inser|ted in \|
|00001460| 63 6f 64 65 7b 73 79 73 | 2e 6d 6f 64 75 6c 65 73 |code{sys|.modules|
|00001470| 7d 2e 0d 5c 65 6e 64 7b | 66 75 6e 63 64 65 73 63 |}..\end{|funcdesc|
|00001480| 7d 0d 0d 54 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |}..The f|ollowing|
|00001490| 20 63 6f 6e 73 74 61 6e | 74 73 20 77 69 74 68 20 | constan|ts with |
|000014a0| 69 6e 74 65 67 65 72 20 | 76 61 6c 75 65 73 2c 20 |integer |values, |
|000014b0| 64 65 66 69 6e 65 64 20 | 69 6e 20 74 68 65 20 6d |defined |in the m|
|000014c0| 6f 64 75 6c 65 2c 0d 61 | 72 65 20 75 73 65 64 20 |odule,.a|re used |
|000014d0| 74 6f 20 69 6e 64 69 63 | 61 74 65 20 74 68 65 20 |to indic|ate the |
|000014e0| 73 65 61 72 63 68 20 72 | 65 73 75 6c 74 20 6f 66 |search r|esult of|
|000014f0| 20 5c 63 6f 64 65 7b 69 | 6d 70 2e 66 69 6e 64 5f | \code{i|mp.find_|
|00001500| 6d 6f 64 75 6c 65 7d 2e | 0d 0d 5c 62 65 67 69 6e |module}.|..\begin|
|00001510| 7b 64 61 74 61 64 65 73 | 63 7d 7b 53 45 41 52 43 |{datades|c}{SEARC|
|00001520| 48 5f 45 52 52 4f 52 7d | 0d 54 68 65 20 6d 6f 64 |H_ERROR}|.The mod|
|00001530| 75 6c 65 20 77 61 73 20 | 6e 6f 74 20 66 6f 75 6e |ule was |not foun|
|00001540| 64 2e 0d 5c 65 6e 64 7b | 64 61 74 61 64 65 73 63 |d..\end{|datadesc|
|00001550| 7d 0d 0d 5c 62 65 67 69 | 6e 7b 64 61 74 61 64 65 |}..\begi|n{datade|
|00001560| 73 63 7d 7b 50 59 5f 53 | 4f 55 52 43 45 7d 0d 54 |sc}{PY_S|OURCE}.T|
|00001570| 68 65 20 6d 6f 64 75 6c | 65 20 77 61 73 20 66 6f |he modul|e was fo|
|00001580| 75 6e 64 20 61 73 20 61 | 20 73 6f 75 72 63 65 20 |und as a| source |
|00001590| 66 69 6c 65 2e 0d 5c 65 | 6e 64 7b 64 61 74 61 64 |file..\e|nd{datad|
|000015a0| 65 73 63 7d 0d 0d 5c 62 | 65 67 69 6e 7b 64 61 74 |esc}..\b|egin{dat|
|000015b0| 61 64 65 73 63 7d 7b 50 | 59 5f 43 4f 4d 50 49 4c |adesc}{P|Y_COMPIL|
|000015c0| 45 44 7d 0d 54 68 65 20 | 6d 6f 64 75 6c 65 20 77 |ED}.The |module w|
|000015d0| 61 73 20 66 6f 75 6e 64 | 20 61 73 20 61 20 63 6f |as found| as a co|
|000015e0| 6d 70 69 6c 65 64 20 63 | 6f 64 65 20 6f 62 6a 65 |mpiled c|ode obje|
|000015f0| 63 74 20 66 69 6c 65 2e | 0d 5c 65 6e 64 7b 64 61 |ct file.|.\end{da|
|00001600| 74 61 64 65 73 63 7d 0d | 0d 5c 62 65 67 69 6e 7b |tadesc}.|.\begin{|
|00001610| 64 61 74 61 64 65 73 63 | 7d 7b 43 5f 45 58 54 45 |datadesc|}{C_EXTE|
|00001620| 4e 53 49 4f 4e 7d 0d 54 | 68 65 20 6d 6f 64 75 6c |NSION}.T|he modul|
|00001630| 65 20 77 61 73 20 66 6f | 75 6e 64 20 61 73 20 64 |e was fo|und as d|
|00001640| 79 6e 61 6d 69 63 61 6c | 6c 79 20 6c 6f 61 64 61 |ynamical|ly loada|
|00001650| 62 6c 65 20 73 68 61 72 | 65 64 20 6c 69 62 72 61 |ble shar|ed libra|
|00001660| 72 79 2e 0d 5c 65 6e 64 | 7b 64 61 74 61 64 65 73 |ry..\end|{datades|
|00001670| 63 7d 0d 0d 5c 73 75 62 | 73 65 63 74 69 6f 6e 7b |c}..\sub|section{|
|00001680| 45 78 61 6d 70 6c 65 73 | 7d 0d 54 68 65 20 66 6f |Examples|}.The fo|
|00001690| 6c 6c 6f 77 69 6e 67 20 | 66 75 6e 63 74 69 6f 6e |llowing |function|
|000016a0| 20 65 6d 75 6c 61 74 65 | 73 20 74 68 65 20 64 65 | emulate|s the de|
|000016b0| 66 61 75 6c 74 20 69 6d | 70 6f 72 74 20 73 74 61 |fault im|port sta|
|000016c0| 74 65 6d 65 6e 74 3a 0d | 0d 5c 62 65 67 69 6e 7b |tement:.|.\begin{|
|000016d0| 76 65 72 62 61 74 69 6d | 7d 0d 69 6d 70 6f 72 74 |verbatim|}.import|
|000016e0| 20 69 6d 70 0d 69 6d 70 | 6f 72 74 20 73 79 73 0d | imp.imp|ort sys.|
|000016f0| 0d 64 65 66 20 5f 5f 69 | 6d 70 6f 72 74 5f 5f 28 |.def __i|mport__(|
|00001700| 6e 61 6d 65 2c 20 67 6c | 6f 62 61 6c 73 3d 4e 6f |name, gl|obals=No|
|00001710| 6e 65 2c 20 6c 6f 63 61 | 6c 73 3d 4e 6f 6e 65 2c |ne, loca|ls=None,|
|00001720| 20 66 72 6f 6d 6c 69 73 | 74 3d 4e 6f 6e 65 29 3a | fromlis|t=None):|
|00001730| 0d 20 20 20 20 23 20 46 | 61 73 74 20 70 61 74 68 |. # F|ast path|
|00001740| 3a 20 73 65 65 20 69 66 | 20 74 68 65 20 6d 6f 64 |: see if| the mod|
|00001750| 75 6c 65 20 68 61 73 20 | 61 6c 72 65 61 64 79 20 |ule has |already |
|00001760| 62 65 65 6e 20 69 6d 70 | 6f 72 74 65 64 2e 0d 20 |been imp|orted.. |
|00001770| 20 20 20 69 66 20 73 79 | 73 2e 6d 6f 64 75 6c 65 | if sy|s.module|
|00001780| 73 2e 68 61 73 5f 6b 65 | 79 28 6e 61 6d 65 29 3a |s.has_ke|y(name):|
|00001790| 0d 20 20 20 20 20 20 20 | 20 72 65 74 75 72 6e 20 |. | return |
|000017a0| 73 79 73 2e 6d 6f 64 75 | 6c 65 73 5b 6e 61 6d 65 |sys.modu|les[name|
|000017b0| 5d 0d 0d 20 20 20 20 23 | 20 49 66 20 61 6e 79 20 |].. #| If any |
|000017c0| 6f 66 20 74 68 65 20 66 | 6f 6c 6c 6f 77 69 6e 67 |of the f|ollowing|
|000017d0| 20 63 61 6c 6c 73 20 72 | 61 69 73 65 73 20 61 6e | calls r|aises an|
|000017e0| 20 65 78 63 65 70 74 69 | 6f 6e 2c 0d 20 20 20 20 | excepti|on,. |
|000017f0| 23 20 74 68 65 72 65 27 | 73 20 61 20 70 72 6f 62 |# there'|s a prob|
|00001800| 6c 65 6d 20 77 65 20 63 | 61 6e 27 74 20 68 61 6e |lem we c|an't han|
|00001810| 64 6c 65 20 2d 2d 20 6c | 65 74 20 74 68 65 20 63 |dle -- l|et the c|
|00001820| 61 6c 6c 65 72 20 68 61 | 6e 64 6c 65 20 69 74 2e |aller ha|ndle it.|
|00001830| 0d 0d 20 20 20 20 23 20 | 53 65 65 20 69 66 20 69 |.. # |See if i|
|00001840| 74 27 73 20 61 20 62 75 | 69 6c 74 2d 69 6e 20 6d |t's a bu|ilt-in m|
|00001850| 6f 64 75 6c 65 2e 0d 20 | 20 20 20 6d 20 3d 20 69 |odule.. | m = i|
|00001860| 6d 70 2e 69 6e 69 74 5f | 62 75 69 6c 74 69 6e 28 |mp.init_|builtin(|
|00001870| 6e 61 6d 65 29 0d 20 20 | 20 20 69 66 20 6d 3a 0d |name). | if m:.|
|00001880| 20 20 20 20 20 20 20 20 | 72 65 74 75 72 6e 20 6d | |return m|
|00001890| 0d 0d 20 20 20 20 23 20 | 53 65 65 20 69 66 20 69 |.. # |See if i|
|000018a0| 74 27 73 20 61 20 66 72 | 6f 7a 65 6e 20 6d 6f 64 |t's a fr|ozen mod|
|000018b0| 75 6c 65 2e 0d 20 20 20 | 20 6d 20 3d 20 69 6d 70 |ule.. | m = imp|
|000018c0| 2e 69 6e 69 74 5f 66 72 | 6f 7a 65 6e 28 6e 61 6d |.init_fr|ozen(nam|
|000018d0| 65 29 0d 20 20 20 20 69 | 66 20 6d 3a 0d 20 20 20 |e). i|f m:. |
|000018e0| 20 20 20 20 20 72 65 74 | 75 72 6e 20 6d 0d 0d 20 | ret|urn m.. |
|000018f0| 20 20 20 23 20 53 65 61 | 72 63 68 20 74 68 65 20 | # Sea|rch the |
|00001900| 64 65 66 61 75 6c 74 20 | 70 61 74 68 20 28 69 2e |default |path (i.|
|00001910| 65 2e 20 73 79 73 2e 70 | 61 74 68 29 2e 0d 20 20 |e. sys.p|ath).. |
|00001920| 20 20 66 70 2c 20 70 61 | 74 68 6e 61 6d 65 2c 20 | fp, pa|thname, |
|00001930| 28 73 75 66 66 69 78 2c | 20 6d 6f 64 65 2c 20 74 |(suffix,| mode, t|
|00001940| 79 70 65 29 20 3d 20 69 | 6d 70 2e 66 69 6e 64 5f |ype) = i|mp.find_|
|00001950| 6d 6f 64 75 6c 65 28 6e | 61 6d 65 29 0d 0d 20 20 |module(n|ame).. |
|00001960| 20 20 23 20 53 65 65 20 | 77 68 61 74 20 77 65 20 | # See |what we |
|00001970| 67 6f 74 2e 0d 20 20 20 | 20 74 72 79 3a 0d 20 20 |got.. | try:. |
|00001980| 20 20 20 20 20 20 69 66 | 20 74 79 70 65 20 3d 3d | if| type ==|
|00001990| 20 69 6d 70 2e 43 5f 45 | 58 54 45 4e 53 49 4f 4e | imp.C_E|XTENSION|
|000019a0| 3a 0d 20 20 20 20 20 20 | 20 20 20 20 20 20 72 65 |:. | re|
|000019b0| 74 75 72 6e 20 69 6d 70 | 2e 6c 6f 61 64 5f 64 79 |turn imp|.load_dy|
|000019c0| 6e 61 6d 69 63 28 6e 61 | 6d 65 2c 20 70 61 74 68 |namic(na|me, path|
|000019d0| 6e 61 6d 65 29 0d 20 20 | 20 20 20 20 20 20 69 66 |name). | if|
|000019e0| 20 74 79 70 65 20 3d 3d | 20 69 6d 70 2e 50 59 5f | type ==| imp.PY_|
|000019f0| 53 4f 55 52 43 45 3a 0d | 20 20 20 20 20 20 20 20 |SOURCE:.| |
|00001a00| 20 20 20 20 72 65 74 75 | 72 6e 20 69 6d 70 2e 6c | retu|rn imp.l|
|00001a10| 6f 61 64 5f 73 6f 75 72 | 63 65 28 6e 61 6d 65 2c |oad_sour|ce(name,|
|00001a20| 20 70 61 74 68 6e 61 6d | 65 2c 20 66 70 29 0d 20 | pathnam|e, fp). |
|00001a30| 20 20 20 20 20 20 20 69 | 66 20 74 79 70 65 20 3d | i|f type =|
|00001a40| 3d 20 69 6d 70 2e 50 59 | 5f 43 4f 4d 50 49 4c 45 |= imp.PY|_COMPILE|
|00001a50| 44 3a 0d 20 20 20 20 20 | 20 20 20 20 20 20 20 72 |D:. | r|
|00001a60| 65 74 75 72 6e 20 69 6d | 70 2e 6c 6f 61 64 5f 63 |eturn im|p.load_c|
|00001a70| 6f 6d 70 69 6c 65 64 28 | 6e 61 6d 65 2c 20 70 61 |ompiled(|name, pa|
|00001a80| 74 68 6e 61 6d 65 2c 20 | 66 70 29 0d 0d 20 20 20 |thname, |fp).. |
|00001a90| 20 20 20 20 20 23 20 53 | 68 6f 75 6c 64 6e 27 74 | # S|houldn't|
|00001aa0| 20 67 65 74 20 68 65 72 | 65 20 61 74 20 61 6c 6c | get her|e at all|
|00001ab0| 2e 0d 20 20 20 20 20 20 | 20 20 72 61 69 73 65 20 |.. | raise |
|00001ac0| 49 6d 70 6f 72 74 45 72 | 72 6f 72 2c 20 27 25 73 |ImportEr|ror, '%s|
|00001ad0| 3a 20 75 6e 6b 6e 6f 77 | 6e 20 6d 6f 64 75 6c 65 |: unknow|n module|
|00001ae0| 20 74 79 70 65 20 28 25 | 64 29 27 20 25 20 28 6e | type (%|d)' % (n|
|00001af0| 61 6d 65 2c 20 74 79 70 | 65 29 0d 20 20 20 20 66 |ame, typ|e). f|
|00001b00| 69 6e 61 6c 6c 79 3a 0d | 20 20 20 20 20 20 20 20 |inally:.| |
|00001b10| 23 20 53 69 6e 63 65 20 | 77 65 20 6d 61 79 20 65 |# Since |we may e|
|00001b20| 78 69 74 20 76 69 61 20 | 61 6e 20 65 78 63 65 70 |xit via |an excep|
|00001b30| 74 69 6f 6e 2c 20 63 6c | 6f 73 65 20 66 70 20 65 |tion, cl|ose fp e|
|00001b40| 78 70 6c 69 63 69 74 6c | 79 2e 0d 20 20 20 20 20 |xplicitl|y.. |
|00001b50| 20 20 20 66 70 2e 63 6c | 6f 73 65 28 29 0d 5c 65 | fp.cl|ose().\e|
|00001b60| 6e 64 7b 76 65 72 62 61 | 74 69 6d 7d 0d |nd{verba|tim}. |
+--------+-------------------------+-------------------------+--------+--------+